// 路由鉴权
import router from "@/routers/index.js";
// import store from './store'
// import { Message } from 'element-ui'
import { getToken } from "@/utils/auth.js";
// import { getCookie } from "@/utils/cookies.js";

const whiteList = ["/login", "/register"]; // 不重定向白名单
router.beforeEach((to, from, next) => {
  // let token = getCookie('SESSIONID')
  console.log('ajsjassa', getToken());
  console.log('to', to.path);

  if (getToken()) {
    if (to.path === "/login" || to.path === "/register") {
      // if (window._hmt) {
      //   window._hmt.push(["_trackPageview", "/#" + to.fullPath]);
      // }
      console.log(11111111);

      next({ path: "/home" });
    } else {
      next();
    }
  } else {
    // 没有token 去白名单路由
    if (whiteList.indexOf(to.path) !== -1) {
      console.log('白名单111', 2222, to.path);
      next();
    } else {
      // 没有白名单 没有token 就去login
      next('/login')
      console.log('白名单222', 2222, to.path);
    }
  }
});
